package com.dps.omc.utils.server;

import com.dps.common.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * Created by DXH on 2016/5/23.
 */
@Service
public class ServerManager {

    @Autowired
    private UnixTest unixTest;
    @Autowired
    private WindowsTest windowsTest;

    private ServerService getServerType(String opSystem){

        if (opSystem.equals(Constants.CENTOS_OP_SYSTEM )){
            return unixTest;
        }else if (opSystem.equals(Constants.WIN_OP_SYSTEM)){
            return windowsTest;
        }
        return null;
    }

    public String testConnect(ServerConnect serverConnect) throws IOException {

        ServerService serverService = getServerType(serverConnect.getOpSystem());
        if (serverService == null){
            return "暂不支持该种服务器类型！";
        }
        boolean res = serverService.testConnect(serverConnect);
        if (res){
            return "连接成功！";
        }else {
            return "连接失败，请检查参数！";
        }
    }

}

